package main.Q2001_2100;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Q2031_2040 {
    public static void main(String[] args) {
        System.out.println("Question2031：");
        System.out.println("Question2032：至少在两个数组中出现的值");
        System.out.println("Question2033：");
        System.out.println("Question2034：");
        System.out.println("Question2035：");
        System.out.println("Question2036：");
        System.out.println("Question2037：");
        System.out.println("Question2038：");
        System.out.println("Question2039：");
        System.out.println("Question2040：");
    }
}

class Question2032{
    public List<Integer> twoOutOfThree(int[] nums1, int[] nums2, int[] nums3) {
        Set<Integer> total=new HashSet<>(),set1=new HashSet<>(),
                set2=new HashSet<>(),set3=new HashSet<>();
        int i=0,j=0,k=0;
        List<Integer> result=new ArrayList<>();
        while (i<nums1.length||j< nums2.length||k< nums3.length) {
            if (i< nums1.length) {
                total.add(nums1[i]);
                set1.add(nums1[i]);
                i++;
            }
            if (j< nums2.length) {
                total.add(nums2[j]);
                set2.add(nums2[j]);
                j++;
            }
            if (k< nums3.length) {
                total.add(nums3[k]);
                set3.add(nums3[k]);
                k++;
            }
        }
        for (int num:total) {
            int count=0;
            if (set1.contains(num)) count++;
            if (set2.contains(num)) count++;
            if (set3.contains(num)) count++;
            if (count>=2) result.add(num);
        }
        return result;
    }
}